/**
 * 
 */
package com.pocketpets.service;

/**
 * @author leo
 * 
 */
public abstract class ServiceFactory {

	// ================================================================
	// Fields
	// ================================================================

	private static ServiceFactory instance = JsonServiceFactory.getInstance();
	private final IService[] services = new IService[ServiceType.values().length];

	public IService getService(ServiceType st) {
		int idx = st.ordinal();
		if (null == services[idx]) {
			services[idx] = instance.doGetService(st);
		}
		return services[idx];
	}

	abstract protected IService doGetService(ServiceType serviceType);

	static public ServiceFactory getDefaultInstance() {
		return instance;
	}

}
